package com.adaydayup.week_1014;

public class CustomStack_1381 {
    int top, size;
    int[] stk;

    public CustomStack_1381(int maxSize) {
        stk = new int[maxSize + 1];
        size = maxSize;
        top = 0;
    }

    public void push(int x) {
        if (top < size) stk[top++] = x;
    }

    public int pop() {
        if (top == 0) {
            return -1;
        }
        return stk[--top];
    }

    public void increment(int k, int val) {
        for (int i = 0; i < k && i < top; ++i) {
            stk[i] += val;
        }
    }

    public static void main(String[] args) {
        CustomStack_1381 custom = new CustomStack_1381(3);
        custom.push(1);
        custom.push(2);
        custom.pop();
        custom.push(2);
        custom.push(3);
        custom.push(4);
        custom.increment(5,100);
        custom.increment(2,100);
        custom.pop();
        custom.pop();
        custom.pop();
        custom.pop();
    }
}
